<?php

function buildTreeCategoryOption($catData, $prentsID = 0) {
    $specs = '&nbsp;';
    foreach ($catData as $aCat) {

        if ($aCat['category_parent'] == $prentsID) {
            if($aCat['category_level'] == 0){
                $style = 'style=color:#F58516;';
            }
            if ($aCat['category_level'] == 1) {
                $specs = '&nbsp;&nbsp;&nbsp;';
            }
            if ($aCat['category_level'] == 2) {
                $specs = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }
            if ($aCat['category_level'] == 3) {
                $specs = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
            }
            $catList .= "<option value=" . $aCat['category_id'] . "  $style>" . $specs . $aCat['category_name'] . "</option>";
            $catList .= buildTreeCategoryOption($catData, $aCat['category_id']);
        }
    }
    return $catList;
}

$strCatOption = buildTreeCategoryOption($aryCategory);
?>
<form id="frmAddCategoryNews" name="frmAddCategoryNews" class="add-category round_border">
    <div class="chosen_category">
        Chọn danh mục cha
    </div>
    <div class="list-item-category">
        <div id="news_1">
            <select class="w170p" size="15" id="selectnews1" onclick="AdminController.checkExistNewsCategory(this.value, 1);">
                <option value="0">Danh mục gốc</option>
                <?php foreach ($aryNewsCategory as $key => $value) {
                ?>
                    <option value="<?php echo $value['news_category_id']; ?>">&nbsp;<?php echo $value['news_category_name']; ?><?php echo ($value['news_category_total_child'] > 0 ) ? ' >' : ''; ?></option>
                <?php } ?>
            </select>
        </div>
        <div id="news_2" class="hide">
            <select class="w170p" size="15" id="selectnews2" onclick="AdminController.checkExistNewsCategory(this.value, 2);">
            </select>
        </div>
    </div>
    <div id="input-item-news">
        <div id="item-0">
            <span>Tên danh mục con</span>
            <span><input type="text" name="news_category_name[]" class="w150p"></span>
            <span>
                <select name="news_product_category_id[]">
                    <option value="0">Danh mục liên quan</option>
                    <?php echo $strCatOption;?>
                </select>
            </span>
            <span>
                <select name="news_category_is_show[]" style="width: 100px;">
                    <option value="1">Hiển thị</option>
                    <option value="0">Không hiển thị</option>
                </select>
            </span>
            <span><a class="cpointer" onclick="AdminController.addRowItemCategory('input-item-news', 'input-item-news-hidden');"><img src="<?php echo $sub_domain;?>/images/form/add-icon.png"></a></span>
            <span style="padding-left: 20px;"><a class="cpointer" onclick="AdminController.removeRowItemCategory(this, 'input-item-news');"><img src="<?php echo $sub_domain;?>/images/form/delete.png"></a></span>
        </div>
    </div>
    <div>
        <input type="button" class="cpointer submit" onclick="AdminController.saveNewsCategory();" value="Thêm">
    </div>
    <input type="hidden" name="news_cat_id_hidden" id="news_cat_id_hidden">
</form>
<div id="input-item-news-hidden" style="display: none;">
    <span>Tên danh mục con</span>
            <span><input type="text" name="news_category_name[]" class="w150p"></span>
            <span>
                <select name="news_product_category_id[]">
                    <option value="0">Danh mục liên quan</option>
                    <?php echo $strCatOption;?>
                </select>
            </span>
            <span>
                <select name="news_category_is_show[]" style="width: 100px;">
                    <option value="1">Hiển thị</option>
                    <option value="0">Không hiển thị</option>
                </select>
            </span>
            <span><a class="cpointer" onclick="AdminController.addRowItemCategory('input-item-news', 'input-item-news-hidden');"><img src="<?php echo $sub_domain;?>/images/form/add-icon.png"></a></span>
            <span style="padding-left: 20px;"><a class="cpointer" onclick="AdminController.removeRowItemCategory(this, 'input-item-news');"><img src="<?php echo $sub_domain;?>/images/form/delete.png"></a></span>
</div>
